
Imports cmplib01

Public Class frmResourceCostPicker
    Inherits System.Windows.Forms.Form

    Const c_Module = "frmResourceCostPicker"

    Private ptrCGD As CampaignerGameData
    Private m_Cancelpressed As Boolean


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents lstResourceTypes As System.Windows.Forms.ListBox
    Friend WithEvents numCost As System.Windows.Forms.NumericUpDown
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnCancel = New System.Windows.Forms.Button
        Me.btnOK = New System.Windows.Forms.Button
        Me.lstResourceTypes = New System.Windows.Forms.ListBox
        Me.numCost = New System.Windows.Forms.NumericUpDown
        CType(Me.numCost, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnCancel
        '
        Me.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnCancel.Location = New System.Drawing.Point(94, 296)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(56, 23)
        Me.btnCancel.TabIndex = 10
        Me.btnCancel.Text = "Cancel"
        '
        'btnOK
        '
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.Location = New System.Drawing.Point(30, 296)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(56, 23)
        Me.btnOK.TabIndex = 9
        Me.btnOK.Text = "OK"
        '
        'lstResourceTypes
        '
        Me.lstResourceTypes.Location = New System.Drawing.Point(8, 8)
        Me.lstResourceTypes.Name = "lstResourceTypes"
        Me.lstResourceTypes.Size = New System.Drawing.Size(144, 251)
        Me.lstResourceTypes.TabIndex = 7
        '
        'numCost
        '
        Me.numCost.Location = New System.Drawing.Point(8, 264)
        Me.numCost.Maximum = New Decimal(New Integer() {32000, 0, 0, 0})
        Me.numCost.Minimum = New Decimal(New Integer() {1, 0, 0, 0})
        Me.numCost.Name = "numCost"
        Me.numCost.Size = New System.Drawing.Size(144, 20)
        Me.numCost.TabIndex = 11
        Me.numCost.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.numCost.Value = New Decimal(New Integer() {1, 0, 0, 0})
        '
        'frmResourceCostPicker
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(160, 326)
        Me.Controls.Add(Me.numCost)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.lstResourceTypes)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Name = "frmResourceCostPicker"
        Me.Text = "Resource Cost"
        CType(Me.numCost, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub PopulateResources()
        Dim res As ResourceType
        Dim reskey As String

        If ptrCGD.ResourceTypes_g.Count = 0 Then
            MessageBox.Show("There are no defined resource types. You must create some first.", "No Resources")
            m_Cancelpressed = True
            Me.Hide()
            Exit Sub
        End If

        For Each reskey In ptrCGD.ResourceTypes_g.HT.Keys
            lstResourceTypes.Items.Add(ptrCGD.ResourceTypes_g.Item(reskey))
        Next

    End Sub

    Public WriteOnly Property CGD() As CampaignerGameData
        Set(ByVal Value As CampaignerGameData)
            ptrCGD = Value
            PopulateResources()
        End Set
    End Property

    Public ReadOnly Property SelectedResourceType() As ResourceType
        Get
            If Not lstResourceTypes.SelectedItem Is Nothing Then Return lstResourceTypes.SelectedItem

        End Get
    End Property

    Public ReadOnly Property Cost() As Integer
        Get
            Return numCost.Value
        End Get
    End Property

    Public ReadOnly Property CancelPressed() As Boolean
        Get
            Return m_Cancelpressed
        End Get
    End Property

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        m_Cancelpressed = True
        Me.Hide()
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If lstResourceTypes.SelectedItem Is Nothing Then
            MessageBox.Show("You must select a resource type before continuing.", "Select a Resource Type")
            Exit Sub
        End If
        m_Cancelpressed = False
        Me.Hide()
    End Sub
End Class
